package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * List集合的演示
 */
public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:" + list);//[one, two, three, four, five]

        list.add(3, "six");//在下标为3的位置插入six
        System.out.println("list:" + list);//[one, two, three, six,four, five]

        list.add(6, "seven");//在list下标为6的位置插入seven
        System.out.println("list:" + list);//list:[one, two, three, six,four, five,seven]

        //list.remove(2);//删除下标为2的元素----常规操作
        String s = list.remove(2);//删除下标为2的元素，并将被删除元素返回给s
        System.out.println(s);//three
        System.out.println("list:" + list);//list:[one, two, six, four, five, seven]

    }
}
